import CustomSelect from '@/components/antd-comp/select/CustomSelect'
import { userContext } from '@/contexts/userContext'
import { getAssistantModelsApi } from '@/controllers/API/assistant'
import { useContext, useEffect, useState } from 'react'

export default function ModelSelect({ value, onChange }) {
  const { user } = useContext(userContext)
  const [configServers, setConfigServers] = useState([])
  const loadModels = async () => {
    const data = await getAssistantModelsApi(user.enterprise_id)
    setConfigServers(data)
  }

  useEffect(() => {
    loadModels()
  }, [])

  return (
    <CustomSelect
      style={{ width: '100%', marginTop: '10px' }}
      value={value}
      placeholder="选择一个模型"
      fieldNames={{ label: 'model_name', value: 'id' }}
      onChange={onChange}
      options={configServers}
    ></CustomSelect>
  )
}
